package com.example.coursehub.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * API根控制器
 * 提供API状态和基本信息
 */
@RestController
@RequestMapping("/api")
public class ApiController {

    /**
     * API根路径 - 返回API状态信息
     * @return API状态和可用端点信息
     */
    @GetMapping
    public ResponseEntity<Map<String, Object>> getApiInfo() {
        Map<String, Object> response = new HashMap<>();
        response.put("status", "success");
        response.put("message", "CourseHub API is running");
        response.put("version", "1.0.0");
        
        Map<String, String> endpoints = new HashMap<>();
        endpoints.put("users", "/api/users");
        endpoints.put("courses", "/api/courses");
        endpoints.put("classes", "/api/classes");
        endpoints.put("chapters", "/api/chapters");
        endpoints.put("exercises", "/api/exercises");
        endpoints.put("materials", "/api/materials");
        endpoints.put("statistics", "/api/statistics");
        
        response.put("endpoints", endpoints);
        
        return ResponseEntity.ok(response);
    }

    /**
     * API健康检查
     * @return 健康状态
     */
    @GetMapping("/health")
    public ResponseEntity<Map<String, Object>> healthCheck() {
        Map<String, Object> response = new HashMap<>();
        response.put("status", "healthy");
        response.put("timestamp", System.currentTimeMillis());
        return ResponseEntity.ok(response);
    }
}